package com.example.demo.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;

public class JsonUtil {

    static ObjectMapper objectMapper=new ObjectMapper();
    public static <T> T toJsonObject(String str,Class<T> clazz){
        if(Objects.isNull(str)){
            return null;
        }
        try {
            return objectMapper.readValue(str, clazz);
        }catch (JsonProcessingException e){
            throw new RuntimeException("josn parse error",e);
        }
    }
}
